package com.peaker.advertisingpro.base

import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.peaker.advertisingpro.utils.Common
import com.peaker.advertisingpro.utils.SPUtil
import com.peaker.advertisingpro.utils.SmdtManagerUtils
import com.peaker.advertisingpro.utils.Utils

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/3/25.
 *  代码人生
 */
open class BaseActivity : AppCompatActivity() {
    var isOpenActivity = false
    lateinit var handler1: Handler
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        handler1 = Handler()
    }

    override fun onStop() {
        super.onStop()
        var runningForeground = Utils.isRunningForeground(this)
        if (!runningForeground) {
            isOpenActivity = true
            //todo  15秒后打开app
            handler1.postDelayed(Runnable {
                if (isOpenActivity) {
                    if (SPUtil.getSP(Common.PROTECT,"关 ") == "开") {
                        Utils.openActivity(this)
                    }
                }
            }, 30_000)

        }

    }

    override fun onDestroy() {
        super.onDestroy()
//        TCPClient.build().closeTcp()
    }

    override fun onResume() {

        super.onResume()
        isOpenActivity = false
    }
}